package com.nbgs.demo.dao;

import com.nbgs.demo.controller.info.BillConsumptionInfo;
import com.nbgs.demo.model.Complain;
import com.nbgs.demo.model.PaymentRecords;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {

    //通过水卡卡号与状态来找到对应的所有账单
    @Select("SELECT " +"t1.bill_id,"+
            "t2.consumption_month,t1.consumption_volume,t1.payable,t1.overdue,t1.bill_state,t1.bill_generate_time " +
            "from t_waterbill t1 JOIN t_consumption t2 ON t1.consumption_id=t2.consumption_id " +
            "WHERE t1.card_id=#{cardId} and  t1.bill_state=CONCAT(#{billState1}) OR t1.bill_state=CONCAT(#{billState2})")
    List<BillConsumptionInfo> findWaterBillByCardNum(int cardId, String billState1, String billState2);

    //通过这个水卡卡号去获得对应的id
    @Select("select card_id from t_card where card_num=CONCAT(#{cardNum})")
    int findCardIdByCardNum(String cardNum);

    //通过billid给账单修改状态--已缴
    @Update("UPDATE t_waterbill SET bill_state='已缴' WHERE bill_id=#{billId};")
    void updateByBillId(int billId);

    //生成缴费信息表
    @Insert("INSERT INTO t_payment_records " +
                   "(payment_date,pay_money,card_id,consumption_month,consumption_volume) " +
                   "VALUES " +
                   "(CONCAT(#{paymentDate}),#{payMoney},#{cardId},CONCAT(#{consumptionMonth}),#{consumptionVolume})")
    void addPaymentRecords(PaymentRecords paymentRecords);


    //生成投诉表
    @Insert("insert into t_complain " +
            "(card_id,complain_type,complain_tel,complain_message,complain_start_date,complain_state) " +
            "values " +
            "(#{cardId},CONCAT(#{complainType}),CONCAT(#{complainTel}),CONCAT(#{complainMessage}),CONCAT(#{complainStartData}),CONCAT(#{complainState}))")
    void addComplain(Complain complain);

    //查询投诉表
    @Select("SELECT\n" +
            "t_complain.complain_id,\n" +
            "t_complain.card_id,\n" +
            "t_complain.complain_type,\n" +
            "t_complain.complain_tel,\n" +
            "t_complain.complain_message,\n" +
            "t_complain.complain_start_date,\n" +
            "t_complain.complain_end_date,\n" +
            "t_complain.complain_state\n" +
            "FROM t_complain WHERE card_id=#{cardId}")
    List<Complain> findComplainByCardId(int cardId);
}
